function refresh() {
	ajaxSendHelper();
}

function setLogin(data) {
	var sec_players = document.getElementById('sec_players');
	htmldata = "<form action='index.php' method='post'>";
	htmldata += "<table><tr><td><input type='hidden' name='cmd' value='login'/>";
	var ulen = data.users.length;
	for ( var i=0, len=ulen; i<len; ++i ){
		var u = data.users[i];
		htmldata += "<tr><td><input type='radio' name='id' value='"+u.name+"' />"+u.name+" ("+u.level+")</td></tr>";
	}
	htmldata += "<td><input type='submit' name='SubmitForm' value='Ok' /></td></tr></table></form>";
	sec_players.innerHTML = htmldata;
}

function ajaxSendHelper() {
	$.ajax({
		url: "index.php",
		type: "POST",
		dataType: "json",
		success: function(data) {
			if (data.redirect != null)
				window.location = data.redirect;
			else
				setLogin(data);
		},
        error: function (xhr, ajaxOptions, thrownError){
			//alert("Exception was thrown");
			//alert(xhr.responseText);
			//var sec_debug = document.getElementById('sec_debug');
            //sec_debug.innerHTML = xhr.responseText;
        }   
	});
}